#ifndef __MEDIASOURCEFiLTER_H_
#define __MEDIASOURCEFiLTER_H_

#include <streams.h>
#include "utility/asyncio.h"
#include "utility/asyncrdr.h"
#include "tmediasource.h"

class TMediaStream : public CAsyncStream
{
public:
    TMediaStream();
    bool Initialize(TMediaSource* pSource);
    HRESULT SetPointer(LONGLONG llPos);
    HRESULT Read(PBYTE pbBuffer,DWORD dwBytesToRead, BOOL bAlign,LPDWORD pdwBytesRead);
    LONGLONG Size(LONGLONG *pSizeAvailable);
    DWORD Alignment();
    void Lock();
    void Unlock();
private:
    CCritSec         m_csLock;
    TMediaSource*    m_pSource;
    long long        m_size;
};

class TMediaSourceFilter : public CAsyncReader
{
public:
    TMediaSourceFilter(HRESULT *phr);
    ~TMediaSourceFilter();
    STDMETHODIMP Register() { return S_OK; };
    STDMETHODIMP Unregister() { return S_OK; };
    void ClearStream();
    bool UpdateStream(TMediaSource *pSource, const CMediaType* mediaType = NULL);
    virtual void OnMediaComplete();
private:
    TMediaStream  m_stream;
};


#endif //__MEDIASOURCEFiLTER_H_